﻿Imports System.Text

Public Class clsProject
    Implements ICloneable
    Public Peaks As Int32
    Public PlanedTimes As StringBuilder
    Public Nr As Int32
    Public Jobs As Int32
    Public RelDate As Int32
    Public DueDate As Int32
    Public TardCost As Int32
    Public MPMTime As Int32
    Public InputFile As String
    Public Generation As Int32
    Public GenerationType As String
    Friend Tasks As Dictionary(Of Int32, clsTask)
    Friend TasksA As List(Of clsTask)

    'Friend Tasks() As clsTask
    Public CriticalPath As New HashSet(Of String)

    Friend RenewableResources As Dictionary(Of String, Int32)
    'Friend RestrictedResources As Hashtable

    Friend RenewableResourcesMax As Int32
    'Friend RestrictedResourcesMax As Int32

    Friend TimeLine As Hashtable

    Public Fitness As Single
    Public BiasedFitness As Single
    Public MaxDistance As Single

    Public ActivtyList As HashSet(Of Int32)
    Public PeakSum As Single
    Public PeakResource()() As Int32
    Public Diagramm()()() As Int32


    Public Function Clone(Optional ByVal reset As Boolean = True, Optional ByVal al_r As Boolean = False) As clsProject
        Dim myClone As New clsProject '= Me.MemberwiseClone()
        'If Not Me.Tasks Is Nothing Then myClone.Tasks = CloneDictionary(Of Int32, clsTask)(Me.Tasks)
        'myClone.TasksA = Nothing
        'ReDim myClone.TasksA(Me.TasksA.Length - 1)
        Dim a As Int32 = 0
        myClone.TasksA = New List(Of clsTask)
        'For Each task As clsTask In Me.TasksA
        '    myClone.TasksA.Add(task.Clone(False))
        '    a += 1
        'Next

        ' myClone.TasksA = New List(Of clsTask)(Me.TasksA)
        TasksA.ForEach(Sub(item)
                           myClone.TasksA.Add(item.Clone1())
                       End Sub)


        'myClone.TasksA = DeepClone(Me.TasksA)

        'myClone.TasksA = New List(Of clsTask)(Me.TasksA)
        If reset Then
            'For Each task As clsTask In myClone.Tasks.Values
            '    'reset auf MPM
            '    task.FAZ = task.MPMFAZ
            '    task.FEZ = task.MPMFEZ
            '    task.SAZ = task.MPMSAZ
            '    task.SEZ = task.MPMSEZ
            '    task.Puffer = task.MPMPuffer
            '    task.PlanedAt = 0
            '    task.PriorityValue = 0
            '    task.SelectProbability = 0
            '    task.RegretValue1 = 0
            '    task.RegretValue2 = 0
            'Next
            Dim i As Int32 = 1
            Dim len As Int32 = myClone.TasksA.Count - 1
            For i = 1 To len
                Dim task As clsTask = myClone.TasksA(i)
                'reset auf MPM
                task.FAZ = task.MPMFAZ
                task.FEZ = task.MPMFEZ
                task.SAZ = task.MPMSAZ
                task.SEZ = task.MPMSEZ
                task.Puffer = task.MPMPuffer
                task.PlanedAt = 0
                task.PriorityValue = 0
                task.SelectProbability = 0
                task.RegretValue1 = 0
                task.RegretValue2 = 0
                i += 1
            Next
        End If
        If Not Me.CriticalPath Is Nothing Then myClone.CriticalPath = CloneHashSet(Of String)(Me.CriticalPath) ' New HashSet(Of String)(Me.CriticalPath)
        If Not Me.RenewableResources Is Nothing Then myClone.RenewableResources = New Dictionary(Of String, Int32)(Me.RenewableResources)
        If Not Me.TimeLine Is Nothing Then myClone.TimeLine = New Hashtable(Me.TimeLine)
        If al_r Then
            myClone.ActivtyList = New HashSet(Of Int32)
        Else
            If Not Me.ActivtyList Is Nothing Then myClone.ActivtyList = CloneHashSet(Of Int32)(Me.ActivtyList) 'New HashSet(Of Int32)(Me.ActivtyList)
        End If
        If Not Me.PeakResource Is Nothing Then myClone.PeakResource = Me.PeakResource.Clone
        If Not Me.Diagramm Is Nothing Then myClone.Diagramm = Me.Diagramm.Clone

        With myClone
            .Nr = Me.Nr
            .Jobs = Me.Jobs
            .RelDate = Me.RelDate
            .DueDate = Me.DueDate
            .TardCost = Me.TardCost
            .MPMTime = Me.MPMTime
            .InputFile = Me.InputFile
            .Generation = Me.Generation
            .GenerationType = Me.GenerationType
            .Fitness = Me.Fitness
            .BiasedFitness = Me.BiasedFitness
            .PlanedTimes = Me.PlanedTimes
            .Peaks = Me.Peaks
            .PeakSum = Me.PeakSum
            .MaxDistance = Me.MaxDistance
        End With

        Return myClone
    End Function
    Public Sub New()

    End Sub

    Public Function Clone1() As Object Implements ICloneable.Clone
        Return Me.MemberwiseClone
    End Function
End Class
